package com.poetry.controller.user;

import com.poetry.domain.dto.NotesDTO;
import com.poetry.domain.po.Notes;
import com.poetry.exception.BasePage;
import com.poetry.exception.R;
import com.poetry.service.INotesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("/notes")
@Tag(name = "笔记模块管理")
public class NotesController {
    @Resource
    private INotesService notesService;

    @Operation(summary = "添加笔记")
    @PostMapping("/add_notes")
    public R<Integer> addNotes(@RequestBody NotesDTO notesDTO) {
        return notesService.addNotes(notesDTO);
    }

    @Operation(summary = "获取我的笔记")
    @PostMapping("/of/me")
    public R<List<Notes>> queryMyNotes(@RequestBody BasePage basePage) {
        return notesService.queryNotes(basePage);
    }

    @Operation(summary = "更新笔记")
    @PutMapping("/update_notes")
    public R<String> updateNotes(@RequestBody Notes notes) {
        return notesService.update(notes);
    }

    @Operation(summary = "删除笔记")
    @DeleteMapping("/delete_notes/{id}")
    public R<String> deleteNotes(@PathVariable Integer id) {
        return notesService.delete(id);
    }

    @Operation(summary = "获取笔记详情")
    @GetMapping("/get/{id}")
    public R<Notes> getById(@PathVariable("id") Integer id) {
        return R.success("获取笔记详情成功", notesService.getById(id));
    }
}
